package javaapplication4;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;


public class LeerAtributoXML {
  public static void main(String[] argv) throws Exception {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser parser = factory.newSAXParser();
    SaxHandler handler = new SaxHandler();
    parser.parse("C:\\Users\\ahmateu\\Desktop\\trabajo\\sample.xml", handler);
  }

}
class SaxHandler extends DefaultHandler {
  public void startElement(String uri, String localName, String qName, Attributes attrs)throws SAXException {
    if (qName.equals("cfdi:Emisor")) {//etiqueta
      String name = attrs.getValue("nombre"); //atributo
      System.out.println("Nombre es '" + name + "'");
    }
  }
}